package com.songshuang.myutilsboot.controller;

import com.songshuang.myutilsboot.common.util.URLUtil;
import com.songshuang.myutilsboot.service.IPdfService;
import com.songshuang.myutilsboot.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/pdf")
public class PdfController {
    @Autowired
    private IPdfService pdfService;
    @PostMapping("/pdfToPng")
    public Result<List<String>> pdfToPng(@RequestParam("pdfFile") MultipartFile pdfFile){
        return pdfService.pdfToPng(pdfFile);
    }

    @GetMapping("/downLoadImage")
    public ResponseEntity<Resource> downLoadImage(@RequestParam("encodeImagePath") String encodeImagePath){
        String imagePath = URLUtil.decode(encodeImagePath);
        return pdfService.downLoadImage(imagePath);
    }
}
